package love.yuanmengrobot.qdkaoqin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import love.yuanmengrobot.qdkaoqin.R;
import love.yuanmengrobot.qdkaoqin.entity.Clazz;
import love.yuanmengrobot.qdkaoqin.entity.Member;

public class MemberTAdapter  extends ArrayAdapter<Member> {


    private List<Member> mMemberData;
    private Context mContext;
    private int resourceId;
    public MemberTAdapter(Context context,
                        int resourceId, List<Member> data) {
        super(context, resourceId, data);
        this.mContext = context;
        this.mMemberData = data;
        this.resourceId = resourceId;
    }
    @Override
    public View getView(int position,
                        View convertView, ViewGroup parent) {
        Member member = getItem(position);
        View view ;
        final MemberTAdapter.ViewHolder vh;
        if (convertView == null) {
            view = LayoutInflater.from(getContext())
                    .inflate(resourceId, parent, false);
            vh = new MemberTAdapter.ViewHolder();
            vh.tvMembername  = view.findViewById(R.id.tv_desc_member_name);
            vh.tvMemberid = view.findViewById(R.id.tv_desc_member_id);

            view.setTag(vh);/////**
        } else {
            view = convertView;
            vh = (MemberTAdapter.ViewHolder) view.getTag();
        }
        vh.tvMembername.setText(member.getName());
        String memberDesc="";
        if("0".equals(member.getPermission())){
            memberDesc="工号："+member.getLoginid()+"(教师)";
        }else {
            memberDesc="学号："+member.getLoginid();
        }
        vh.tvMemberid.setText(memberDesc);

        return view;
    }
    class ViewHolder {
        TextView tvMembername;
        TextView tvMemberid;
    }


}
